package com.hice.demo.sbdbra.web;

import com.alibaba.dubbo.config.annotation.Reference;
import com.hice.demo.sbdbra.common.redis.RedisUtil;
import com.hice.demo.sbdbra.model.User;
import com.hice.demo.sbdbra.service.ActiveMQService;
import com.hice.demo.sbdbra.service.UserService;
import org.apache.log4j.Logger;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

/**
 * 登录控制器
 */
@RestController
public class LoginController {
    private Logger logger = Logger.getLogger(getClass());
    @Reference(version = "1.0.0")
    ActiveMQService activeMQService;
    @Reference(version = "1.0.0")
    UserService userService;

    @RequestMapping("/queue")
    public String queue(String txt) {
        activeMQService.sendQueue(txt);
        return "OK";
    }

    @RequestMapping("/topic")
    public String topic(String txt) {
        activeMQService.sendTopic(txt);
        return "OK";
    }

    @RequestMapping("/redis")
    public String redis() {
        RedisUtil.set("hice", "89757", 300L, TimeUnit.SECONDS);
        return "No";
    }

    @RequestMapping("/getRedis")
    public Object getRedis() {
        Object hice = RedisUtil.get("hice", null);
        return hice;
    }

    @RequestMapping("/regist")
    public String regist(String name, int age) {
        User member = new User();
//		member.setUserId(15646465465465L);
        member.setUserName(name);
        member.setAge(age);
        return userService.register(member) ? "true" : "false";
    }

    @RequestMapping("/login")
    public String login(String name, int age) {
        User member = new User();
        member.setUserName(name);
        member.setAge(age);
        return userService.login(member) ? "true" : "false";
    }

}
